from django.db import models

import auth.models
import core.models
import securities.models

class Portfolio(core.models.BaseModel):
  user = models.ForeignKey(auth.models.User, reverse_name='portfolios')
  name = models.CharField(max_length=50)

class Transaction(core.models.BaseModel):
  portfolio = models.ForeignKey(Portfolio)
  date = models.DateField()
  notes = models.TextField()
  type = models.SmallIntegerField()
  
  def verboseType(self):
    return self.ORDER_TYPES[self.type]
  
  class Meta:
    abstract = True
    
class CashTransaction(Transaction):
  ORDER_TYPES = (
    (0, 'Deposit'),
    (1, 'Withdrawal'),
  )
  value = models.FloatField()

class SecurityTransaction(Transaction):
  ORDER_TYPES = (
    (0, 'Buy'),
    (1, 'Sell'),
    (2, 'Buy to Cover'),
    (3, 'Sell Short'),
  )
  security = models.ForeignKey(securities.models.Security)
  shares = models.FloatField()
  price = models.FloatField()
  commission = models.FloatField()